<template>
  <div class="home-container">
    <el-row :gutter="20">
      <!-- 统计卡片 -->
      <el-col :span="6" v-for="(stat, index) in statistics" :key="index">
        <el-card :body-style="{ padding: '20px' }" class="stat-card" shadow="hover">
          <div class="stat-content">
            <el-icon :size="24" :class="stat.iconClass">
              <component :is="stat.icon" />
            </el-icon>
            <div class="stat-info">
              <div class="stat-value">{{ stat.value }}</div>
              <div class="stat-label">{{ stat.label }}</div>
            </div>
          </div>
          <div class="stat-footer">
            <span>{{ stat.change }}</span>
            <span :class="stat.trend">
              {{ stat.trend === 'up' ? '↑' : '↓' }} {{ stat.percentage }}
            </span>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="chart-row">
      <!-- 任务执行趋势 -->
      <el-col :span="16">
        <el-card class="chart-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span>任务执行趋势</span>
              <el-radio-group v-model="timeRange" size="small">
                <el-radio-button label="week">本周</el-radio-button>
                <el-radio-button label="month">本月</el-radio-button>
                <el-radio-button label="year">全年</el-radio-button>
              </el-radio-group>
            </div>
          </template>
          <div class="chart-placeholder">
            图表区域（需要集成图表库如 ECharts）
          </div>
        </el-card>
      </el-col>

      <!-- 最近活动 -->
      <el-col :span="8">
        <el-card class="activity-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span>最近活动</span>
              <el-button text>查看全部</el-button>
            </div>
          </template>
          <div class="activity-list">
            <div v-for="(activity, index) in recentActivities" :key="index" class="activity-item">
              <el-avatar :size="32" :src="activity.avatar" />
              <div class="activity-content">
                <div class="activity-title">{{ activity.title }}</div>
                <div class="activity-time">{{ activity.time }}</div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="task-row">
      <!-- 待处理任务 -->
      <el-col :span="12">
        <el-card class="task-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span>待处理任务</span>
              <el-button text>更多</el-button>
            </div>
          </template>
          <el-table :data="pendingTasks" style="width: 100%" :max-height="300">
            <el-table-column prop="name" label="任务名称" />
            <el-table-column prop="priority" label="优先级" width="100">
              <template #default="scope">
                <el-tag :type="scope.row.priority === '高' ? 'danger' : scope.row.priority === '中' ? 'warning' : 'info'">
                  {{ scope.row.priority }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="deadline" label="截止时间" width="180" />
          </el-table>
        </el-card>
      </el-col>

      <!-- 系统状态 -->
      <el-col :span="12">
        <el-card class="status-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <span>系统状态</span>
              <el-button text>详情</el-button>
            </div>
          </template>
          <div class="status-list">
            <div v-for="(status, index) in systemStatus" :key="index" class="status-item">
              <div class="status-label">{{ status.label }}</div>
              <el-progress 
                :percentage="status.value" 
                :status="status.value > 80 ? 'exception' : status.value > 60 ? 'warning' : 'success'"
                :stroke-width="10"
              />
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { 
  Connection, 
  Timer, 
  User, 
  List 
} from '@element-plus/icons-vue'

const timeRange = ref('week')

const statistics = ref([
  {
    label: '总任务数',
    value: '1,234',
    icon: List,
    iconClass: 'stat-icon-blue',
    change: '周同比',
    trend: 'up',
    percentage: '12%'
  },
  {
    label: '运行中任务',
    value: '32',
    icon: Timer,
    iconClass: 'stat-icon-green',
    change: '日环比',
    trend: 'up',
    percentage: '8%'
  },
  {
    label: '活跃用户',
    value: '802',
    icon: User,
    iconClass: 'stat-icon-orange',
    change: '周同比',
    trend: 'down',
    percentage: '3%'
  },
  {
    label: '系统负载',
    value: '67%',
    icon: Connection,
    iconClass: 'stat-icon-purple',
    change: '日环比',
    trend: 'up',
    percentage: '5%'
  }
])

const recentActivities = ref([
  {
    avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    title: '张三 完成了 发票处理任务',
    time: '10分钟前'
  },
  {
    avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    title: '李四 创建了新应用',
    time: '1小时前'
  },
  {
    avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    title: '系统 完成了数据备份',
    time: '2小时前'
  }
])

const pendingTasks = ref([
  {
    name: '月度报表生成',
    priority: '高',
    deadline: '2024-03-31 23:59:59'
  },
  {
    name: '数据同步任务',
    priority: '中',
    deadline: '2024-03-30 18:00:00'
  },
  {
    name: '系统日志分析',
    priority: '低',
    deadline: '2024-04-01 12:00:00'
  }
])

const systemStatus = ref([
  {
    label: 'CPU使用率',
    value: 65
  },
  {
    label: '内存使用率',
    value: 45
  },
  {
    label: '存储空间',
    value: 82
  },
  {
    label: '网络带宽',
    value: 30
  }
])
</script>

<style scoped>
.home-container {
  padding: 20px;
}

.stat-card {
  height: 120px;
  transition: all 0.3s;
}

.stat-card:hover {
  transform: translateY(-5px);
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
  line-height: 1.2;
}

.stat-label {
  font-size: 14px;
  color: #909399;
  margin-top: 4px;
}

.stat-footer {
  margin-top: 16px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  color: #909399;
}

.stat-icon-blue {
  color: #409EFF;
}

.stat-icon-green {
  color: #67C23A;
}

.stat-icon-orange {
  color: #E6A23C;
}

.stat-icon-purple {
  color: #909399;
}

.up {
  color: #67C23A;
}

.down {
  color: #F56C6C;
}

.chart-row {
  margin-top: 20px;
}

.chart-card, .activity-card {
  height: 400px;
}

.task-row {
  margin-top: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-placeholder {
  height: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f5f7fa;
  color: #909399;
  border-radius: 4px;
}

.activity-list {
  height: 320px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #EBEEF5;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-content {
  flex: 1;
}

.activity-title {
  font-size: 14px;
  color: #303133;
}

.activity-time {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
}

.status-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.status-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-label {
  font-size: 14px;
  color: #606266;
}

:deep(.el-card__header) {
  padding: 15px 20px;
  border-bottom: 1px solid #EBEEF5;
}

:deep(.el-table) {
  --el-table-header-bg-color: #f5f7fa;
}

:deep(.el-progress-bar__inner) {
  transition: all 0.3s ease;
}

/* 自定义滚动条样式 */
.activity-list::-webkit-scrollbar {
  width: 6px;
}

.activity-list::-webkit-scrollbar-thumb {
  background: #E4E7ED;
  border-radius: 3px;
}

.activity-list::-webkit-scrollbar-track {
  background: #F5F7FA;
}
</style> 